#!/usr/bin/env python
# -*- coding: utf-8 -*-

#
# This program is free software; you can redistribute it and/or modify  
# it under the terms of the GNU General Public License as published by  
# the Free Software Foundation; either version 2 of the License, or     
# (at your option) any later version.                                   
#                                                                         
# A copy of the license can be found in the license.txt file supplied   
# with this software or at: http://www.gnu.org/copyleft/gpl.html       
#

# quick and dirty attempt at a python version of MurmurHash
#http://murmurhash.googlepages.com/
#http://murmurhash.googlepages.com/MurmurHash2.cpp

def hash(s, seed):
    m = 0x5bd1e995
    r = 24
    h = seed ^ len(s)
    for c in s:
        k = ord(c)
        k *= m
        k ^= k >> r
        k *= m
        h *= m
        h ^= k

    #Do a few final mixes of the hash to ensure the last few
    #bytes are well-incorporated.

    h ^= (h >> 13)
    h *= m
    h ^= (h >> 15)
    # loop ups type to long..this fixes it though we seem to be
    # only getting 31 bits :(
    return int(h & 0x7FFFFFFF)

    ## hash()

